package com.gm.wholesale.module.main.presenter

import com.gm.commonlib.util.logUtils.LogUtil
import com.gm.commonlib.views.popupwindow.Popupwindow
import com.gm.wholesale.bluetooth.bean.WeightBean
import com.gm.wholesale.module.good.bean.GoodBean
import com.gm.wholesale.module.main.ui.MainActivity
import com.gm.wholesale.module.order.ui.MainOrderFragment
import com.gm.wholesale.module.order.view.CreateOrderView
import com.gm.wholesale.module.order.view.CreateOrderViewByVoice
import com.gm.wholesale.module.order.view.UpdateOrderViewByVoice

class CreateOrderUiPre(
    private val mActivity: MainActivity,
    private val mMainOrderFragment: MainOrderFragment?) {
    private var createOrderView: CreateOrderView? = null
    private var createOrderViewByVoice: CreateOrderViewByVoice? = null
    private var updateGoodForVoice: UpdateOrderViewByVoice? = null
    fun setNumBer(weightBean: WeightBean?) {
        if (createOrderView != null) {
            createOrderView!!.setBlueNumber(weightBean)
        }
        if (createOrderViewByVoice != null) {
            createOrderViewByVoice!!.setBlueNumber(weightBean)
        }
        if (updateGoodForVoice != null) {
            updateGoodForVoice!!.setBlueNumber(weightBean)
        }
    }

    fun showCreateOrderView(goodBean: GoodBean?) {
        createOrderView = CreateOrderView(mActivity)
        createOrderView?.setICreateOrderListener { goodBean1: GoodBean? ->
            mMainOrderFragment?.addGoodBean(
                goodBean1
            )
        }
        createOrderView?.showChoiceGoodView(mActivity, goodBean)
        Popupwindow.showPopCenterView(mActivity, createOrderView)
    }

    fun createOrder(goodBean: GoodBean?) {
        mMainOrderFragment?.addGoodBean(goodBean)
        LogUtil.d("onResult: 创建成功")
    }

    fun showCreateOrderViewByVoice(goodName: String?) {
        createOrderViewByVoice = CreateOrderViewByVoice(mActivity)
        createOrderViewByVoice!!.setICreateOrderListener { goodBean1: GoodBean? ->
            mMainOrderFragment?.addGoodBean(
                goodBean1
            )
        }
        createOrderViewByVoice!!.showViewByVoice(mActivity, goodName)
        Popupwindow.showPopCenterView(mActivity, createOrderViewByVoice)
        LogUtil.d("onResult 跳转界面创建 成功")
    }

    fun updateGoodForVoice(goodBean: GoodBean?) {
        updateGoodForVoice = UpdateOrderViewByVoice(mActivity)
        updateGoodForVoice!!.setICreateOrderListener { goodBean1: GoodBean? ->
            mMainOrderFragment?.addGoodBean(
                goodBean1
            )
        }
        updateGoodForVoice!!.updateGoodForVoice(mActivity, goodBean)
        Popupwindow.showPopCenterView(mActivity, updateGoodForVoice)
    }
}